package com.jxc.dao.impl;

import java.sql.SQLException;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.jxc.dao.TransportDao;
import com.jxc.entity.Transport;
import com.jxc.util.PageBean;

public class TransportDaoImpl extends HibernateDaoSupport implements TransportDao{

	public void deletetransport(Transport transport) {
		// TODO Auto-generated method stub
		getHibernateTemplate().delete(this.gettransport(transport));
	}

	public Transport gettransport(Transport transport) {
		// TODO Auto-generated method stub
		return (Transport)getHibernateTemplate().get(Transport.class,transport.getId());
	}

	public void gettransportlist(final String hql, final PageBean bean) {
		getHibernateTemplate().execute(new HibernateCallback() {
			
			public Object doInHibernate(Session session) throws HibernateException,
					SQLException {
				Query query=session.createQuery(hql);
				bean.setTotalitem(query.list().size());
				query.setFirstResult((bean.getPageon()-1)*bean.getPagesize());
				query.setMaxResults(bean.getPagesize());
				bean.setList(query.list());
				return null;
			}
		});
	}

	public void inserttransport(Transport transport) {
		// TODO Auto-generated method stub
		getHibernateTemplate().save(transport);
	}

	public void updatetransport(Transport transport) {
		// TODO Auto-generated method stub
		getHibernateTemplate().update(transport);
	}

}
